package com.mall.controller;

import com.mall.pojo.PmsSkuStock;
import com.mall.service.PmsSkuStockService;
import com.mall.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {

    @Autowired
    private PmsSkuStockService pmsSkuStockService;

    //批量更新sku库存信息
    @PostMapping("/update/{pid}")
    public Result<PmsSkuStock> update(@PathVariable("pid") Integer pid,
                                      @RequestBody PmsSkuStock pmsSkuStock) {
        pmsSkuStockService.update(pid, pmsSkuStock);
        return Result.success(null, "操作成功");
    }

    //根据商品ID及sku编码模糊搜索sku库存
    @GetMapping("/{pid}")
    public Result<PmsSkuStock> selectBuId(@PathVariable("pid") Integer pid,
                                          @RequestParam(value = "keyword", required = false) String keyword) {
        PmsSkuStock pmsSkuStock = pmsSkuStockService.selectById(pid, keyword);
        return Result.success(pmsSkuStock, "操作成功");
    }

}
